<?php
namespace app\admin\controller;
use think\Controller;
use think\Request;

class Base extends Controller
{
    public function _initialize(){
        if(!session('?admin_user')){
            $this->error('请先登录系统！','Pub/login');
        }
        
        $request = Request::instance();
        //获取当前控制器名
        $con = $request->controller();
        //获取当前方法名
        $action = $request->action();
        //控制器/方法
        $name=$con.'/'.$action;
        // var_dump($name);

        $admin_user = session('admin_user'); //获取权限列表

        // var_dump($admin_user);
        // var_dump(!in_array($action,$admin_user['node'][$con]));
        // var_dump(empty($admin_user['node'][$con]));

        // die();
        //让超级管理员admin拥有所有权限
        if($admin_user['a_username'] != 'admin'){
            //验证操作权限
            if(empty($admin_user['node'][$con]) || !in_array($action,$admin_user['node'][$con])){
                
                $this->error("抱歉！没有操作权限！");
                exit;
            }

        }
    }
}
